<template>
  <div class="clearfix table-out search">
    <el-button
      type="primary"
      plain
      size="small"
      class="return pointer"
      @click="returnGo"
      ><i class="iconfont icon-fanhui"></i> 返回
    </el-button>

    <div class="clearfix top-return search-pub">
      <el-form :model="formData" label-width="auto">
        <el-select class="fxl margin10R" @change="getData(1)"
          v-model="formData.pingszt"
          placeholder="请选择评审状态"
          style="width: 120px"
        >
          <el-option
            v-for="item in pingsztlb"
            :key="item.id"
            :label="item.itemText"
            :value="item.itemValue"
          />
        </el-select>

        <el-select class="fxl margin10R" clearable @change="getData"
                   @clear="getData"
          v-model="formData.saisjc"
          placeholder="请选择赛事进程"
          style="width: 180px">
          <el-option
            v-for="item in saisjclb"
            :key="item.id"
            :label="item.jincmc"
            :value="item.id"
          />
        </el-select>

        <el-input class="fxl margin10R" clearable @clear="getData"
          v-model="formData.zuopbt"
          style="width: 200px"
          placeholder="请输入作品标题"
        />
        <el-cascader class="fxl margin10R" clearable
          @change="change"
          :show-all-levels="true"
          placeholder="请选择赛区"
          :props="props"
          v-model="formData.saiq"
          :options="options"
        ></el-cascader>

        <el-select class="fxl margin10R" @change="getData"
          v-model="formData.zilshjg" clearable
          placeholder="请选择资料审核结果"
          style="width: 200px"
        >
          <el-option
            v-for="item in zilshjglb"
            :key="item.id"
            :label="item.itemText"
            :value="item.itemValue"
          />
        </el-select>

        <el-button class="fxl" type="primary" @click="getData">查询</el-button>
        <el-button class="fxl" type="primary" @click="reset">重置</el-button>
      </el-form>
    </div>

    <el-table
      :data="tableData"
      v-loading="tableLoading"
      class="tablePub top-return"
      :row-class-name="tableRowClassName"
    >
      <!-- <el-table-column prop="no" label="序号" width="70">
        <template #default="scope">
          <p>{{ scope.$index + 1 }}</p>
        </template>
      </el-table-column> -->

      <el-table-column label="序号" type="index" :index="getIndex" width="70" />

      <!-- <el-table-column prop="createBy" label="提交人"></el-table-column> -->
      <el-table-column prop="saiq" label="赛区" width="150"></el-table-column>

      <el-table-column width="140"
        prop="saisjc_dictText"
        label="赛事进程"
      ></el-table-column>
      <el-table-column prop="zuopbt" label="作品"></el-table-column>

      <el-table-column width="120"
        prop="pingszt_dictText"
        label="评审状态"
      ></el-table-column>
      <el-table-column width="180"
        prop="zilshjg_dictText"
        label="资料审核结果"
      ></el-table-column>
      <el-table-column prop="createTime" label="提交时间" width="190"></el-table-column>
      <el-table-column fixed="right" label="操作" width="200">
        <template #default="scope">
          <el-button
                     type="primary"
                     size="small"
                     @click="oper(scope.$index, scope.row,0)"
          >编辑</el-button>
          <el-button v-if="formData.pingszt=='1'"
            type="primary"
            size="small"
            @click="oper(scope.$index, scope.row,1)"
            >资料审核</el-button>
          <el-button  v-if="formData.pingszt=='2'"
              size="small"
              @click="oper(scope.$index, scope.row,2)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        v-model:current-page="pageNo"
        v-model:page-size="pageSize"
      @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
      small
      background
        layout="total, prev, pager, next"
      :total="total"
      class="pagination fxr"
    />
  </div>
</template>

<script>
import pubJs from "./pub";
import axios from "axios";

export default {
  mixins: [pubJs],
  data() {
    return {
      zilshjglb: [],
      pingsztlb: [],
      saisjclb: [],
      options: [],
      props: {
        checkStrictly: true,
        expandTrigger: "click",
        value: "key",
        label: "title",
      },
      formData: {
        pingszt: '1',
        saisjc:'',
        zuopbt:'',
        saiq:'',
      },
      userInfo: JSON.parse(localStorage.getItem("userInfo")),
    };
  },

  inject: ["imageUrl", "serviceUrl"],

  mounted() {
    let that = this;
    that.saisId = this.$route.query.saisId;
    that.getOptionsData("C05");
    that.dictItemList("1782630545334263809")
    that.cdba2SaisjcData()
    this.searchFormData = JSON.parse(localStorage.getItem('searchFormData'))
    if (this.searchFormData&&Object.keys(this.searchFormData).length != 0) {
      this.formData.pingszt = this.searchFormData.pingszt?this.searchFormData.pingszt:''
      this.formData.saisjc = this.searchFormData.saisjc?this.searchFormData.saisjc:''
      this.formData.zuopbt = this.searchFormData.zuopbt?this.searchFormData.zuopbt:''
      this.formData.saiq = this.searchFormData.saiq?this.searchFormData.saiq:''
      this.formData.zilshjg =  this.searchFormData.zilshjg?this.searchFormData.zilshjg:''
      this.pageNo =  this.searchFormData.pageNo?this.searchFormData.pageNo:''
    }
    setTimeout(()=>{
      this.getData(this.pageNo);
    },200)
    
    axios
      .get(that.serviceUrl + "/sys/dictItem/list", {
        headers: {
          "X-Access-Token": localStorage.getItem("token"),
        },
        params: {
          dictId: "1780588172500619266",
          _t: new Date().getTime(),
        },
      })
      .then((resp) => {
        that.zilshjglb = resp.data.result.records;
      })
      .catch((error) => {
        //console.log(error);
      });
  },

  methods: {
    getIndex(index) {
      return (this.pageNo - 1) * this.pageSize + index + 1
    },

    change(e) {
      if(e){
        this.formData.saiq = e[e.length - 1];
      }
      this.getData()
    },
    oper(index, row,num) {
      localStorage.setItem("topStepId", row.saisjc);
      localStorage.setItem('searchFormData',JSON.stringify({...this.formData,pageNo:this.pageNo}))
      this.$router.push({
        path: "zilsh_detail",
        query: {
          id: row.id,
          saisId: row.sais,
          canszpId: row.zuopId,
          saisjcId: row.saisjc,
          pingszt:num,
          zilshjg:row.zilshjg,
        },
      });
    },

    returnGo() {
      this.$router.go(-1); // 返回上一个页面
    },

    reset() {
      console.log(this.searchFormData,'this.searchFormData');
      this.formData = { saisId: this.saisId,pingszt:this.searchFormData&&this.searchFormData.pingszt?this.searchFormData.pingszt:'1' };
      this.pageNo = 1
      this.getData();
    },

    getData(v) {
      let that = this;
      if (this.formData.sqiq != null && this.formData.sqiq.length > 0)
        this.formData.sqiq = this.formData.sqiq[2];
      this.tableLoading = true
      // 作品标题模糊查询
      // if(that.formData.zuopbt)
        // that.formData.zuopbt = "*" + that.formData.zuopbt + "*"
      axios
        .get(that.serviceUrl + "/zilsh2/cbda2Zilsh/list2", {
          headers: {
            "X-Access-Token": localStorage.getItem("token"),
          },
          params: {
            ...this.formData,
            zuopbt:that.formData.zuopbt?'*'+that.formData.zuopbt+'*':'',
            column: "createTime",
            order: "desc",
            pageSize: this.pageSize,
            pageNo:this.pageNo,
            _t: new Date().getTime(),
            sais: that.saisId
          },
        })
        .then((resp) => {
          if(resp&&resp.data.code==200){
            this.tableLoading = false
            that.tableData = resp.data.result.records;
            this.total = resp.data.result.total;
            this.pageSize = resp.data.result.size;
          }
        })
        .catch((error) => {
          //console.log(error);
        });
    },
  },
};
</script>

<style scoped lang="less"></style>
